using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using OnlinePlots.Diagrams;
using OnlinePlots.Plots.DataSets;
using OnlinePlots.Plots.Scales;
using System.Windows;

namespace OnlinePlots.Plots.Elements
{
    /// <summary>
    /// Represents an explicit function plot with set of rendering properties for
    /// displaying in ExplicitFunctionPlotControl control
    /// </summary>
    public class ExplicitFunctionPlotItem : DiagramElement
    {
        protected PlotLineElement plotLine = new PlotLineElement();

        /// <summary>
        /// Creates a new instance of ExplicitFunctionPlotItem
        /// </summary>
        public ExplicitFunctionPlotItem()
            : base()
        {
            plotLine.BindToDiagramElement(this);
        }

        /// <summary>
        /// Creates a new instance of ExplicitFunctionPlotItem and assingns a dataSet to it
        /// </summary>
        /// <param name="dataSet">Data set for the plot</param>
        public ExplicitFunctionPlotItem(PlotDataSet dataSet)
            : this()
        {
            DataSet = dataSet;
        }

        /// <summary>
        /// Creates a new instance of ExplicitFunctionPlotItem with specified name and assingns a dataSet to it
        /// </summary>
        /// <param name="dataSet">Data set for the plot</param>
        /// <param name="name">Name of the plot</param>
        public ExplicitFunctionPlotItem(PlotDataSet dataSet, String name)
            : this(dataSet)
        {
            this.Name = name;
        }

        public static readonly DependencyProperty NameProperty = DependencyProperty.Register(
                "Name",
                typeof(string),
                typeof(ExplicitFunctionPlotItem),
                new PropertyMetadata("New plot")
            );

        /// <summary>
        /// Gets or sets name of the plot
        /// </summary>
        [Description("Name of the plot")]
        public String Name
        {
            get { return (string)GetValue(NameProperty); }
            set { SetValue(NameProperty, value); }
        }

        public static readonly DependencyProperty DataSetProperty = DependencyProperty.Register(
                "DataSet",
                typeof(PlotDataSet),
                typeof(ExplicitFunctionPlotItem),
                new PropertyMetadata(new ContinousPlotDataSet(delegate(double x) { return 0; }))
            );

        /// <summary>
        /// Gets or sets data set for the plot
        /// </summary>
        [Description("Data set of the plot")]
        public PlotDataSet DataSet
        {
            get { return (PlotDataSet)GetValue(DataSetProperty); }
            set { SetValue(DataSetProperty, value); }
        }

        /// <summary>
        /// Gets or sets plot line element of the plot
        /// </summary>
        [Description("Line of the plot")]
        public PlotLineElement PlotLine
        {
            get { return plotLine; }
            set
            {
                plotLine.Unbind();
                plotLine = value;
                plotLine.BindToDiagramElement(this);
            }
        }

        public override string ToString()
        {
            return Name;
        }
    }
}
